
document.addEventListener('DOMContentLoaded', (event) => {
    document.getElementById('sync_data').addEventListener('click', function () {

        // 禁用按钮

        var button = document.getElementById('sync_data');
        button.disabled = true;
        button.innerHTML = '正在同步...';

        fetch('/get_master_station_sensor_data', {
            method: 'POST'
        })
            .then(response => response.json())
            .then(data => {
                console.log('Success:', data);
                if (data.status == 1) {
                    alert('同步成功！');
                    window.location.href = '/';
                } else {
                    alert('同步失败：' + data.errorMsg);
                }
            })
            .catch(error => {
                console.error('Error:', error);
                alert('同步失败：网络错误');
            })

            .finally(() => {
                // 解除禁用按钮
                button.disabled = false;
                button.innerHTML = '同步sensor.db文件';

            });
    });
});